{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>域名列表</h5>
        </div>
        <div class="ibox-content">
            <!--搜索框开始-->           
            <div class="row">
                <div class="col-sm-12">   
                <div  class="col-sm-2" style="width: 340px">
                    <div class="input-group" >  
                      
                        <!--<a onclick="enameDel_wxdanger()"><button class="btn btn-outline btn-primary" type="button">禁用投诉短网站</button></a> -->
                        
                         
                    </div>
                </div>                                            
                    <form name="admin_list_sea" class="form-search" method="post" action="{:url('index')}">
                        <div class="col-sm-3" style="width:40%;">
                            <div class="input-group">
                                <input type="text" id="key" class="form-control" name="key" value="{$val}" placeholder="输入代理id/短网址(http://需要去掉)/主域名/" />  
                                <span class="input-group-btn"> 
                                    <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button> 
									 <!--<input style="margin-left:8px;" type="button" class="btn btn-danger" id="jc_0" value="拦截检查" /> -->
                                </span>
								
                            </div>
                        </div>
                    </form>                         
                </div>
            </div>
            <!--搜索框结束-->
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="table table-bordered table-hover">
                        <thead>
                            <tr class="long-tr">
                                <th>ID</th>
                                <th>代理id</th>
                                <th>短网址</th>
                                
								<th>点击次数</th>
							    <th>创建时间</th>
							    <th>状态</th>
                              
                            </tr>
                        </thead>
                        <script id="list-template" type="text/html">
                            {{# for(var i=0;i<d.length;i++){  }}

                            <tr class="long-td">
                                <td>{{d[i].id}}</td>
                                <td>{{d[i].userid}}</td>
                                <td style="word-wrap: break-word;word-break: break-all;overflow: hidden;">{{d[i].dwz}}</td>
                               
                                
                                
							
                               <td>{{d[i].count}}</td>
                               <td>{{d[i].create_time}}</td>
                               <td>
                                  
                                        {{# if(d[i].status==1){ }}
                                            <a class="red" href="javascript:;" onclick="ename_status({{d[i].id}});">
                                                <div id="zt{{d[i].id}}"><span class="label label-info">开启</span></div>
                                            </a>
                                        {{# }else{ }}
                                            <a class="red" href="javascript:;" onclick="ename_status({{d[i].id}});">
                                                <div id="zt{{d[i].id}}"><span class="label label-danger">禁用</span></div>
                                            </a>
                                        {{# } }}
                                   
                                </td>
                               
                            </tr>
                            {{# } }}
                        </script>
                        <tbody id="list-content"></tbody>
                    </table>
                    <div id="AjaxPage" style=" text-align: right;"></div>
                    <div id="allpage" style=" text-align: right;"></div>
                </div>
            </div>
            <!-- End Example Pagination -->
        </div>
    </div>
</div>
<!-- End Panel Other -->
</div>

<!-- 加载动画 -->
<div class="spiner-example">
    <div class="sk-spinner sk-spinner-three-bounce">
        <div class="sk-bounce1"></div>
        <div class="sk-bounce2"></div>
        <div class="sk-bounce3"></div>
    </div>
</div>

{include file="public/footer" /}
<style>
.jc{ color:#666;border-radius:5px; border:solid 1px #666;padding:2px;font-size:12px;cursor:pointer; }
.jc66{ color:#00CC33;border:solid 1px #00CC33;}
.jc0{ color:#ff0000;border:solid 1px #ff0000;}
.jc88{ color:#ff0000;border:solid 1px #ff0000;}
</style>
<script type="text/javascript">
   
    //laypage分页
    Ajaxpage();
						  $("#jc_0000").on("click",function(){
					          var obj=$(this);
							  var url=$("#key").val();
							  var id=obj.data("id");

							   if(url==""){
							    alert("请输入不带https或http的域名");
								return false;
							   };
							   obj.val("正在检查");
							  $.ajax({
								url:"{:Url('jcsite')}",
								data:{"url":""+url,"id":0},
								type:"post",
								dataType:"json",
								success:function(res){
									//$("#jc_"+res.id).html(res.msg);  
									//var obj=$("#jc_"+res.id);
									layer.msg(res.msg);
									  obj.val("检查");
									//obj.addClass("jc"+res.state);
								}
							  });
							  
					  });
					    $("#jc_0").on("click",function(){
							//$(".jc").each(function(){
							//	var obj=$(this);
							//	var url=obj.data("name");
							//	var id=obj.data("id");
							//	obj.html("正在检查");
							//	$.ajax({
							//		url:"{:Url('jcsite')}",
							//		data:{"url":""+url,"id":id},
							//		type:"post",
							//		dataType:"json",
							//		success:function(res){
							//			$("#jc_"+res.id).html(res.msg);  
							//			var obj=$("#jc_"+res.id);
							//			obj.addClass("jc"+res.state);
							//		}
							//	});
							//});
							
							$(".jc").each(function(idx) {
								var obj=$(this);
							    setTimeout(function () {check(obj) }, idx*4000); 
							});
					});
					
	function check(obj){
		console.log(obj);
		var url=obj.data("name");
		var id=obj.data("id");
		obj.html("正在检查");
		$.ajax({
			url:"{:Url('jcsite')}",
			data:{"url":""+url,"id":id},
			type:"post",
			dataType:"json",
			success:function(res){
				$("#jc_"+res.id).html(res.msg);  
				var obj=$("#jc_"+res.id);
				obj.addClass("jc"+res.state);
			}
		});
	}
    function Ajaxpage(curr){
        var key=$('#key').val();
        $.getJSON('{:url("index")}', {page: curr || 1,key:key}, function(data){
            $(".spiner-example").css('display','none'); //数据加载完关闭动画 
            if(data==''){
                $("#list-content").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
            }else{
                var tpl = document.getElementById('list-template').innerHTML;
                laytpl(tpl).render(data, function(html){
                    document.getElementById('list-content').innerHTML = html;
					$(".jc").each(function(){
					  $(this).on("click",function(){
					       var obj=$(this);
							  var url=obj.data("name");
							  var id=obj.data("id");
							  obj.html("正在检查");
							  $.ajax({
								url:"{:Url('jcsite')}",
								data:{"url":""+url,"id":id},
								type:"post",
								dataType:"json",
								success:function(res){
									$("#jc_"+res.id).html(res.msg);  
									var obj=$("#jc_"+res.id);
									obj.addClass("jc"+res.state);
								}
							  });
					  })

					});
                });
                laypage({
                    cont: $('#AjaxPage'),//容器。值支持id名、原生dom对象，jquery对象,
                    pages:'{$allpage}',//总页数
                    skip: true,//是否开启跳页
                    skin: '#1AB5B7',//分页组件颜色
                    curr: curr || 1,
                    groups: 3,//连续显示分页数
                    jump: function(obj, first){
                        if(!first){
                            Ajaxpage(obj.curr)
                        }
                        $('#allpage').html('第'+ obj.curr +'页，共'+ obj.pages +'页');
                    }
                });
            }
        });
    }

//编辑用户
function enameEdit(id){
    location.href = './edit/id/'+id+'.html';
}

//删除用户
function enameDel(id){
    dashang.confirm(id,'{:url("del")}');
}

// //删除所有被微信封了的域名
// function enameDel_wxdanger(){
//     dashang.confirm(0,'{:url("del_wxdanger")}');
// }

//用户状态
function ename_status(id){
    
    dashang.status(id,'{:url("status")}');
}

</script>
</body>
</html>